﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.SessionState;
using System.Text;

namespace ReportTracking.Services
{
    /// <summary>
    /// Summary description for PL2Result
    /// </summary>
    public class PL2Result : IHttpHandler, IReadOnlySessionState
    {

        public void ProcessRequest(HttpContext context)
        {
            context.Response.ContentType = "text/plain";
            StringBuilder sInfo = new StringBuilder();
            InfoReport inforeport = new InfoReport();
            inforeport = (InfoReport)context.Session["InfoReprot"];
            sInfo.Append("{");
            sInfo.Append("\"Info\":");
            sInfo.Append("{");
            if (inforeport != null)
            {

                sInfo.Append("\"fd\":\"");
                sInfo.Append(inforeport.FromDay);
                sInfo.Append("\",");
                sInfo.Append("\"td\":\"");
                sInfo.Append(inforeport.ToDay);
                sInfo.Append("\",");
                sInfo.Append("\"total\":");
                sInfo.Append(inforeport.Total);
                sInfo.Append(",");
                sInfo.Append("\"Type\":");
                sInfo.Append(inforeport.ReportType);
                sInfo.Append(",");
                sInfo.Append("\"DVKD\":");
                sInfo.Append("\"");
                if (inforeport.DVKD == null)
                {
                    sInfo.Append("Tất cả");

                }
                else
                {
                    if (inforeport.DVKD.Length > 1)
                    {

                        for (int i = 0; i < inforeport.DVKD.Length; i++)
                        {
                            sInfo.Append(inforeport.DVKD[i]);
                            sInfo.Append(";");
                        }
                        sInfo.Replace(";", "", sInfo.Length - 2, 1);
                    }
                    else if (inforeport.DVKD.Length > 0)
                    {
                        sInfo.Append(inforeport.DVKD[0]);
                    }
                }

                sInfo.Append("\"");
            }
            sInfo.Append("}");
            sInfo.Append("}");
            context.Response.Write(sInfo.ToString());
        }

        public bool IsReusable
        {
            get
            {
                return false;
            }
        }
    }
}